//导入axios实例
import { instance } from "@/request"
// 封装http请求
class Http {
  static BASE_URL = "http://localhost:3000"
  static getHttp(url) {
    return new Promise((resolve, reject) => {
      instance.get(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  static postHttp(url, msg) {
    return new Promise((resolve, reject) => {
      instance.post(this.BASE_URL + url, msg).then((res) => {
        resolve(res)
      })
    })
  }
  static putHttp(url, msg) {
    return new Promise((resolve, reject) => {
      instance.put(this.BASE_URL + url, msg).then((res) => {
        resolve(res)
      })
    })
  }
  static deleteHttp(url) {
    return new Promise((resolve, reject) => {
      instance.delete(this.BASE_URL + url).then((res) => {
        resolve(res)
      })
    })
  }
  // 请求交通部门用户
  static getTrafficMembers(msg) {
    return this.getHttp(`/users/traffic?page=${msg.page}&offset=${msg.offset}`)
  }
  //请求普通部门用户
  static getNormalMembers(msg) {
    return this.getHttp(`/users/normal?page=${msg.page}&offset=${msg.offset}`)
  }
  //模糊查询用户
  static getSearch(msg) {
    return this.getHttp(`/users/search?keyword=${msg.keyword}&type=${msg.type}`)
  }
  //添加用户
  static addUsers(msg) {
    return this.postHttp(`/users/register`, msg)
  }
  //修改用户信息
  static updateUsers(id, msg) {
    return this.putHttp(`/users/msg/${id}`, msg)
  }
  //修改用户权限
  static updatePower(id, msg) {
    return this.putHttp(`/users/power/${id}`, msg)
  }
  //用户下线
  static underLine(id) {
    return this.putHttp(`/users/online/${id}`)
  }
  //注销用户
  static deleteUsers(id) {
    console.log(id)
    return this.deleteHttp(`/users/logoutmulti?id=${id}`)
  }
  //用户登录
  static userLogin(msg) {
    return this.postHttp(`/users/login`, msg)
  }
  //验证用户登录
  static getLogin() {
    return this.getHttp(`/users/verify`)
  }
}

export { Http }
